package com.eedi.framework.social.dal.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.eedi.framework.common.pojo.PageResult;
import com.eedi.framework.mybatis.core.mapper.BaseMapperX;
import com.eedi.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.eedi.framework.social.enmus.SysSocialTypeEnum;
import org.apache.ibatis.annotations.Mapper;
import com.eedi.framework.social.dal.dataobject.SysSocialUserDO;
import com.eedi.framework.social.controller.sys.vo.user.SysSocialUserPageReq;
@Mapper
public interface SysSocialUserMapper extends BaseMapperX<SysSocialUserDO> {

    default SysSocialUserDO selectByTypeAndCodeAnState(SysSocialTypeEnum type, String code, String state) {
        return selectOne(new LambdaQueryWrapper<SysSocialUserDO>()
                .eq(SysSocialUserDO::getSysSocialUserType, type)
                .eq(SysSocialUserDO::getCode, code)
                .eq(SysSocialUserDO::getState, state));
    }

    default SysSocialUserDO selectByTypeAndOpenid(SysSocialTypeEnum type, String openid) {
        return selectOne(new LambdaQueryWrapper<SysSocialUserDO>()
                .eq(SysSocialUserDO::getSysSocialUserType, type)
                .eq(SysSocialUserDO::getOpenid, openid));
    }

    default PageResult<SysSocialUserDO> selectPage(SysSocialUserPageReq reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<SysSocialUserDO>()
                .eqIfPresent(SysSocialUserDO::getSysSocialUserType, reqVO.getSysSocialType())
                .likeIfPresent(SysSocialUserDO::getNickname, reqVO.getNickname())
                .likeIfPresent(SysSocialUserDO::getOpenid, reqVO.getOpenid())
                .betweenIfPresent(SysSocialUserDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(SysSocialUserDO::getSysSocialUserId));
    }

}
